<?php

/**
 * EmsPortal form base class.
 *
 * @method EmsPortal getObject() Returns the current form's model object
 *
 * @package    ems
 * @subpackage form
 * @author     Jacobo Martínez
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseEmsPortalForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'              => new sfWidgetFormInputHidden(),
      'title'           => new sfWidgetFormInputText(),
      'domain_url'      => new sfWidgetFormInputText(),
      'published'       => new sfWidgetFormInputCheckbox(),
      'is_enabled'      => new sfWidgetFormInputCheckbox(),
      'organization_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('EmsOrganization'), 'add_empty' => false)),
      'css_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('EmsCss'), 'add_empty' => false)),
      'created_at'      => new sfWidgetFormDateTime(),
      'updated_at'      => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'              => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'title'           => new sfValidatorString(array('max_length' => 100)),
      'domain_url'      => new sfValidatorString(array('max_length' => 100)),
      'published'       => new sfValidatorBoolean(array('required' => false)),
      'is_enabled'      => new sfValidatorBoolean(array('required' => false)),
      'organization_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('EmsOrganization'))),
      'css_id'          => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('EmsCss'))),
      'created_at'      => new sfValidatorDateTime(),
      'updated_at'      => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'EmsPortal', 'column' => array('title'))),
        new sfValidatorDoctrineUnique(array('model' => 'EmsPortal', 'column' => array('domain_url'))),
      ))
    );

    $this->widgetSchema->setNameFormat('ems_portal[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'EmsPortal';
  }

}
